package synchronicity.discovery;

import java.util.Vector;

import synchronicity.host.SchedulerHost;

/**
 * For unit testing. Keeps a manual reference to all SchedulerHostImpls by
 * working with a MockSchedulerHostFactory
 */
public class MockDiscovery implements Discovery {

	private static MockDiscovery instance;

	private Vector otherHosts;

	private MockDiscovery() {
		otherHosts = new Vector();
	}

	public synchronized static MockDiscovery getInstance() {
		if (instance == null) {
			instance = new MockDiscovery();
		}
		return instance;
	}

	public synchronized SchedulerHost[] findOtherHosts() {
		SchedulerHost[] result = new SchedulerHost[otherHosts.size()];
		for (int ii = 0; ii < result.length; ii++)
			result[ii] = (SchedulerHost) otherHosts.elementAt(ii);
		return result;
	}

	public synchronized void addHost(SchedulerHost host) {
		if (!otherHosts.contains(host)) {
			otherHosts.addElement(host);
		}
	}

	public synchronized void removeAllHosts() {
		otherHosts.removeAllElements();
	}

}
